var app = getApp();
Page({
  data: {
    searchKw: '',
    pkItemsHideStatus: 2,
    classify: 0,
    code: '',
    animationData: {}
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
  },
  onReady:function(){
    // 页面渲染完成
    var that = this;
    console.log('onReady++++++++++++++++++')
    app.api.login()
  },
  onShow:function(){
    // 页面显示
    var animation = wx.createAnimation({
      duration: 500,
      timingFunction: 'ease-in'
    });

    this.animation = animation;

    animation.opacity(1).step();

    this.setData({
      animationData:animation.export()
    });

    this.setData({
      pkItemsHideStatus: 2,
      pkProductItems: app.globalData.pkItems
    });
  },
  onHide:function(){
    // 页面隐藏
    var animation = wx.createAnimation({
      duration: 100,
      timingFunction: 'ease-out'
    });
    this.animation = animation;

    animation.opacity(1).step();

    this.setData({
      animationData:animation.export()
    });
    this.setData({
      pkItemsHideStatus: 2
    });
  },
  onUnload:function(){
    // 页面关闭
  },
  onShareAppMessage: function () {
    return {
      title: '搜保',
      desc: '搜保智能搜索页',
      path: '/pages/search/index/index'
    }
  },
  getKeyword: function (event) {
    var that = this;
    var keywordSearch =event.detail.value;
    that.setData({
      searchKw: keywordSearch
    });

  },
  gotoSearch: function (event) {
    var that = this;
    var classifyInsurance = that.data.classify;
    var keywordSearch =that.data.searchKw;

    if(keywordSearch){
      that.setData({
        searchKw: keywordSearch
      });
      wx.navigateTo({ url: '/pages/product/index/index?keyword='+ keywordSearch +'&classify='+ classifyInsurance +'' });
    }else{
      wx.showModal({
        title: '提示',
        content: '请输入您要搜索的内容!',
        showCancel: false,
        success: function(res) {
          if (res.confirm) {

          }
        }
      })
    }

  },

  gotoCar: function (){
    wx.navigateTo({ url: '/pages/search/car_insurance/index' });
  },
  gotoSport: function (){
    wx.navigateTo({ url: '/pages/search/sport_insurance/index' });
  },
  gotoTravel: function (){
    wx.navigateTo({ url: '/pages/search/travel_insurance/index' });
  },
  gotoPkSimple: function (event) {
    wx.navigateTo({ url: '/pages/product/pk_simple/index' });
  },
  delPkItem: function (res1) {
    var that = this;
    wx.showModal({
      title: '提示',
      content: '确定删除？',
      success: function (res2) {
        if (res2.confirm) {
          app.delPkItem(app.globalData.pkItems[res1.currentTarget.dataset.index]);
          console.log(app.globalData.pkItems);
          that.setData({
            pkProductItems: app.globalData.pkItems
          })
        }
      }
    })
  },
  pkItemsHide: function(){
    var that = this;
    var _status = that.data.pkItemsHideStatus;
    if(_status==1){
      that.setData({
        pkItemsHideStatus: 2
      })
    }
    if(_status==2){
      that.setData({
        pkItemsHideStatus: 1
      })
    }

  }
});